package com.youboy.wechatapi.repository.message.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.youboy.wechatapi.domain.mysql.BindInfo;
import com.youboy.wechatapi.repository.message.BindRepository;
import com.youboy.wechatapi.utils.curd.MybatisRepositorySupport;

/**
 * @ProjectName：wechatapi
 * @author：冉尧（Yvan）
 * @CreateTime：2014年10月9日 上午9:20:32
 * @Remarks：
 */
@Repository
public class BindRepositoryImpl extends MybatisRepositorySupport<String, BindInfo> 
	implements BindRepository {

	@Override
	protected String getNamespace() {
		return "com.youboy.wechatapi.domain.mysql.BindInfo";
	}

	@Override
	public BindInfo getBindInfo(String openid) throws Exception {
		return getSqlSession().selectOne(getNamespace().concat(".getByOpenId"),openid);
	}

	@Override
	public int count() throws Exception {
		Object countObj = getSqlSession().selectOne(getNamespace().concat(".count")).toString();
		int count = 0;
		if(countObj != null){
			count = Integer.valueOf(countObj.toString());
		}
		return count;
	}

	@Override
	public List<String> getUsPage(int startNo, int pageSize) throws Exception {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startNo", startNo);
		params.put("pageSize", pageSize);
		return getSqlSession().selectList(getNamespace().concat(".getUsPage"), params);
	}
}
